#include "Col.ph"
#ifdef __GNUG__
#pragma implementation
#endif

#include "ObjFloat.h"

#include "Class.h"
#include "String.h"

NewMetaImpl(ObjFloat,Object, (T(val)));

//---- a float object ----------------------------------------------------------

static union {
	unsigned long aslong[2];
	double asdouble;
} hashunion;


u_long ObjFloat::Hash()
{
	hashunion.asdouble= val;
	return hashunion.aslong[0] ^ hashunion.aslong[1];
}

bool ObjFloat::IsEqual(Object* op)
{
	return (bool) (op->IsKindOf(ObjFloat) && val == ((ObjFloat*)op)->val);
}

int ObjFloat::Compare(Object* op)
{
	double t = val - Guard(op, ObjFloat)->val;
	if (t < 0)
		return -1;
	if (t > 0)
		return 1;
	return 0;
}

const char *ObjFloat::AsString()
{
	return form("%g", val);
}

OStream& ObjFloat::PrintOn(OStream &s)
{
	Object::PrintOn(s);
	return s << val SP;
}

IStream& ObjFloat::ReadFrom(IStream &s)
{
	Object::ReadFrom(s);
	return s >> val;
}

